var VERIFY_EERROR = "0";
var NULL_VALUE = "1";
var LOGIN_FAIL = "2";
var LOGIN_SUCC = "3";
var NORMAL = "4";
var FREEZE = "5";
var EXPIRED = "6";
var EMERGENCY = "7";

$(document).ready(function(){
	setCookie(eventId,"");
    $('#loginBtn').click(function(){
        if (checkBrower() == "ie") {
            checkLogin();
        }
        else {
            alert("对不起，本系统暂时不支持mozilla浏览器！");
        }
    });
    //setTimeout(findVerifyCode, 1000);
});

function checkBrower(){
    if ($.browser.mozilla) {    
        //return "mozilla";        
    }
	return "ie"; 
}

$(function(){
    document.onkeydown = function(e){
        var ev = document.all ? window.event : e;
        if (ev.keyCode == 13) {
            checkLogin();
        }
    }
});

function findVerifyCode(){
    var timestamp = Date.parse(new Date());
    $.get("admin/UserServ_findVerifyCode.action?ts=" + timestamp, null, findVerifyCodeRst);
}

function findVerifyCodeRst(data){
    $('#verifyCode').val(data.ajaxRst);
}

function checkLogin(){
    var url = 'admin/LoginOut_checkLogin.action';
    var params = {
        "UId": $('#UId').attr('value'),
        "UPassword": $('#UPassword').attr('value'),
        "verifyCode": $('#verifyCode').attr('value')
    };
    jQuery.post(url, params, checkLoginRst, 'json');
}

function checkLoginRst(data){
    switch (data.ajaxRst) {
        case "0":
            alert("验证码错误");
            break;
        case NULL_VALUE:
            alert("用户名或密码为空");
            break;
        case LOGIN_FAIL:
            alert("用户名或密码错误");
            break;
        case FREEZE:
            alert("账户被冻结");
            break;
        case EXPIRED:
            alert("账户过期");
            break;
        case LOGIN_SUCC:
            window.location.replace("index.jsp");
            break;
        case EMERGENCY:
            window.location.replace("currentEvent.jsp");
            break;
        default:
            alert("登录失败");
    }
}

function show(o){
    var timenow = new Date().getTime();
    o.src = "getImageCode?time=" + timenow;
    setTimeout(function(){
        o.src = "getImageCode?time=" + timenow;
    }, 20);
}
